package 面试相关;

import java.lang.reflect.Array;
import java.util.*;

/**
 * @ClassName 十进制数中1出现的次数
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2022/2/26 19:17
 * Version 1.0
 **/
public class 十进制数中1出现的次数 {
    public static int fun(String s,int[] x,int[] y){
        int res = 0;
        double[] z = new double[x.length];
        char[] chars = s.toCharArray();
        TreeMap map = new TreeMap();
        Set set = new HashSet();
        for(int i = 0; i < x.length; i++){
            z[i] = Math.sqrt(x[i] * x[i] + y[i] * y[i]);
            map.put(z[i],chars[i]);
        }
        System.out.println(map);
        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry next = (Map.Entry) iterator.next();
            if(set.contains(next.getValue())){
                return set.size();
            }
            set.add(next.getValue());
        }
        return set.size();
    }
    public int solution(String S,int[] X,int[] Y){
        int n=S.length();
        Map<Character,Integer> map=new HashMap<>();
        int max=Integer.MAX_VALUE;
        for (int i=0;i<n;i++){
            char c=S.charAt(i);
            if (!map.containsKey(c)){
                map.put(c,X[i]*X[i]+Y[i]*Y[i]);
            }else {
                max=Math.min(Math.max(map.get(c),X[i]*X[i]+Y[i]*Y[i]),max);
            }
        }
        int result=0;
        for (int i=0;i<n;i++){
            if(X[i]*X[i]+Y[i]*Y[i]<max){
                result++;
            }
        }
        return result;
    }
    public static int a(int[] A){
        int min = Integer.MAX_VALUE;
        for(int i = 1; i < A.length - 2; i++){
            for(int j = i + 2; j <= A.length - 2; j++){
                min = Math.min(min,A[i] + A[j]);
            }
        }
        return min;
    }

    public static void main(String[] args) {
        int[] a  = new int[]{5,2,4,6,3,7};
        int a1 = a(a);
        System.out.println(a1);
    }
    public int solution(String A, String B) {
        // write your code in Java SE 8
        int count=0;
        char[] charsA = A.toCharArray();
        char[] charsB = B.toCharArray();

        for(int i=0;i<charsA.length;i++){
            for(int j=i;j<charsA.length;j++){
                HashMap<Character,Integer> hashMap=new HashMap<>();
                for(int m=i;m<=j;m++){
                    if(hashMap.containsKey(charsA[m])){
                        hashMap.put(charsA[m],hashMap.get(charsA[m])+1);
                    }else{
                        hashMap.put(charsA[m],1);
                    }
                }
                for(int m=i;m<=j;m++){
                    if(hashMap.containsKey(charsB[m])){
                        hashMap.put(charsB[m],hashMap.get(charsB[m])-1);
                        if (hashMap.get(charsB[m])==0){
                            hashMap.remove(charsB[m]);
                        }
                    }else{
                        break;
                    }
                }
                if(hashMap.size()==0){
                    count++;
                }
            }
        }
        return count;
    }
}
